<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="我们在上一章学习数码管静态显示的时候说到，74HC138 只能在同一时刻导通一个三极管，而我们的数码管是靠了 6 个三极管来控制，那我们如何来让数码管同时显示呢？这就用到了动态显示的概念。 多个数码管显示数字的时候，我们实际上是轮流点亮数码管（一个时刻内只有一个数码管是亮的），利用人眼的视觉暂留现象（也叫余辉效应），就可以做到看起来是所有数码管都同时亮了，这就是动态显示，也叫做动态扫描。 例如：有">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="6.4、数码管动态显示">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2014/12/01/mcu038/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="我们在上一章学习数码管静态显示的时候说到，74HC138 只能在同一时刻导通一个三极管，而我们的数码管是靠了 6 个三极管来控制，那我们如何来让数码管同时显示呢？这就用到了动态显示的概念。 多个数码管显示数字的时候，我们实际上是轮流点亮数码管（一个时刻内只有一个数码管是亮的），利用人眼的视觉暂留现象（也叫余辉效应），就可以做到看起来是所有数码管都同时亮了，这就是动态显示，也叫做动态扫描。 例如：有">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://c.biancheng.net/cpp/uploads/allimg/140316/1-140316234642303.png">
<meta property="og:updated_time" content="2019-01-27T01:59:00.057Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="6.4、数码管动态显示">
<meta name="twitter:description" content="我们在上一章学习数码管静态显示的时候说到，74HC138 只能在同一时刻导通一个三极管，而我们的数码管是靠了 6 个三极管来控制，那我们如何来让数码管同时显示呢？这就用到了动态显示的概念。 多个数码管显示数字的时候，我们实际上是轮流点亮数码管（一个时刻内只有一个数码管是亮的），利用人眼的视觉暂留现象（也叫余辉效应），就可以做到看起来是所有数码管都同时亮了，这就是动态显示，也叫做动态扫描。 例如：有">
<meta name="twitter:image" content="http://c.biancheng.net/cpp/uploads/allimg/140316/1-140316234642303.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2014/12/01/mcu038/">





  <title>6.4、数码管动态显示 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2014/12/01/mcu038/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">6.4、数码管动态显示</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2014-12-01T20:36:21+08:00">
                2014-12-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/单片机教程/" itemprop="url" rel="index">
                    <span itemprop="name">单片机教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>我们在上一章学习数码管静态显示的时候说到，74HC138 只能在同一时刻导通一个三极管，而我们的数码管是靠了 6 个三极管来控制，那我们如何来让数码管同时显示呢？这就用到了动态显示的概念。</p>
<p>多个数码管显示数字的时候，我们实际上是轮流点亮数码管（一个时刻内只有一个数码管是亮的），利用人眼的视觉暂留现象（也叫余辉效应），就可以做到看起来是所有数码管都同时亮了，这就是动态显示，也叫做动态扫描。</p>
<p>例如：有 2 个数码管，我们要显示“12”这个数字，先让高位的位选三极管导通，然后控制段选让其显示“1”，延时一定时间后再让低位的位选三极管导通，然后控制段选让其显示“2”。把这个流程以一定的速度循环运行就可以让数码管显示出“12”，由于交替速度非常快，人眼识别到的就是“12”这两位数字同时亮了。</p>
<p>那么一个数码管需要点亮多长时间呢？也就是说要多长时间完成一次全部数码管的扫描呢（很明显：整体扫描时间=单个数码管点亮时间*数码管个数）？答案是：10ms 以内。当电视机和显示器还处在 CRT（电子显像管）时代的时候，有一句很流行的广告语——“100Hz无闪烁”，没错，只要刷新率大于 100Hz，即刷新时间小于 10ms，就可以做到无闪烁，这也就是我们的动态扫描的硬性指标。那么你也许会问，有最小值的限制吗？理论上没有，但实际上做到更快的刷新却没有任何进步的意义了，因为已经无闪烁了，再快也还是无闪烁，只是徒然增加 CPU 的负荷而已（因为 1 秒内要执行更多次的扫描程序）。所以，通常我们设计<br>程序的时候，都是取一个接近 10ms，又比较规整的值就行了。我们开发板上有 6 个数码管，那么我们现在就来着手写一个数码管动态扫描的程序，实现兼验证上面讲的动态显示原理。</p>
<p>我们的目标还是实现秒表功能，只不过这次有 6 个位了，最大可以计到 999999 秒。那么现在要实现的这个程序相对于前几章的例程来说就要复杂的多了，既要处理秒表计数，又要处理动态扫描。在编写这类稍复杂的程序时，建议初学者们先用程序流程图来把程序的整个流程理清，在动手写程序之前先把整个程序的结构框架搭好，把每一个环节要实现的功能先细化出来，然后再用程序代码一步一步的去实现出来。这样就可以避免无处下笔的迷茫感了。如图 6-1 就是本例的程序流程图，大家先根据流程图把程序的执行经过在大脑里走一遍，然后再看接下来的程序代码，体会一下流程图的作用，看是不是能帮助你更顺畅的理清程序流程。</p>
<p><img src="http://c.biancheng.net/cpp/uploads/allimg/140316/1-140316234642303.png" alt></p>
<center><strong>图 6-1  数码管动态显示秒表程序流程图</strong></center>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;reg52.h&gt;</span><br><span class="line">sbit ADDR0 = P1^0;</span><br><span class="line">sbit ADDR1 = P1^1;</span><br><span class="line">sbit ADDR2 = P1^2;</span><br><span class="line">sbit ADDR3 = P1^3;</span><br><span class="line">sbit ENLED = P1^4;</span><br><span class="line">unsigned char code LedChar[] = &#123;  //数码管显示字符转换表</span><br><span class="line">    0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,</span><br><span class="line">    0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E</span><br><span class="line">&#125;;</span><br><span class="line">unsigned char LedBuff[6] = &#123; //数码管显示缓冲区，初值 0xFF 确保启动时都不亮</span><br><span class="line">    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF</span><br><span class="line">&#125;;</span><br><span class="line">void main()&#123;</span><br><span class="line">    unsigned char i = 0;  //动态扫描的索引</span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line">    unsigned int cnt = 0; //记录 T0 中断次数</span><br><span class="line">    unsigned long sec = 0; //记录经过的秒数</span><br><span class="line">   </span><br><span class="line">    ENLED = 0;  //使能 U3，选择控制数码管</span><br><span class="line">    ADDR3 = 1; //因为需要动态改变 ADDR0-2 的值，所以不需要再初始化了</span><br><span class="line">   </span><br><span class="line">    TMOD = 0x01;  //设置 T0 为模式 1</span><br><span class="line">    TH0 = 0xFC;  //为 T0 赋初值 0xFC67，定时 1ms</span><br><span class="line">    TL0 = 0x67;</span><br><span class="line">    TR0 = 1;  //启动 T0</span><br><span class="line">    while (1)&#123;</span><br><span class="line">        if (TF0 == 1)&#123;  //判断 T0 是否溢出</span><br><span class="line">            TF0 = 0;  //T0 溢出后，清零中断标志</span><br><span class="line">            TH0 = 0xFC;  //并重新赋初值</span><br><span class="line">            TL0 = 0x67;</span><br><span class="line">            cnt++;  //计数值自加 1</span><br><span class="line">       </span><br><span class="line">            if (cnt &gt;= 1000)&#123; //判断 T0 溢出是否达到 1000 次</span><br><span class="line">                cnt = 0;  //达到 1000 次后计数值清零</span><br><span class="line">                sec++;  //秒计数自加 1</span><br><span class="line">               </span><br><span class="line">                //以下代码将 sec 按十进制位从低到高依次提取并转为数码管显示字符</span><br><span class="line">                LedBuff[0] = LedChar[sec%10];</span><br><span class="line">                LedBuff[1] = LedChar[sec/10%10];</span><br><span class="line">                LedBuff[2] = LedChar[sec/100%10];</span><br><span class="line">                LedBuff[3] = LedChar[sec/1000%10];</span><br><span class="line">                LedBuff[4] = LedChar[sec/10000%10];</span><br><span class="line">                LedBuff[5] = LedChar[sec/100000%10];</span><br><span class="line">            &#125;</span><br><span class="line">            //以下代码完成数码管动态扫描刷新</span><br><span class="line">            if (i == 0)</span><br><span class="line">            &#123; ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=LedBuff[0]; &#125;</span><br><span class="line">            else if (i == 1)</span><br><span class="line">            &#123; ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=LedBuff[1]; &#125;</span><br><span class="line">            else if (i == 2)</span><br><span class="line">            &#123; ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=LedBuff[2]; &#125;</span><br><span class="line">            else if (i == 3)</span><br><span class="line">            &#123; ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=LedBuff[3]; &#125;</span><br><span class="line">            else if (i == 4)</span><br><span class="line">            &#123; ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=LedBuff[4]; &#125;</span><br><span class="line">            else if (i == 5)</span><br><span class="line">            &#123; ADDR2=1; ADDR1=0; ADDR0=1; i=0; P0=LedBuff[5]; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这段程序，大家自己抄到 Keil 中，然后边抄边结合程序流程图来理解，最终下载到实验板上看一下运行结果。其中下边的 if…else 语句就是每 1ms 快速的刷新一个数码管，这样 6个数码管整体刷新一遍的时间就是 6ms，视觉感官上就是 6 个数码管同时亮起来了。</p>
<p>在 C 语言中， /”等同于数学里的除法运算，而“%”等同于我们小学学的求余数运算，这个前边已有介绍。如果是 123456 这个数字，我们要正常显示在数码管上，个位显示，就是直接对 10 取余数，这个“6”就出来了，十位数字就是先除以 10，然后再对 10 取余数，以此类推，就把 6 个数字全部显示出来了。</p>
<p>对于多选一的动态刷新数码管的方式，我们如果用 switch 会有更好的效果，大家来看一下我们用 switch 语句完成的情况。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;reg52.h&gt;</span><br><span class="line">sbit ADDR0 = P1^0;</span><br><span class="line">sbit ADDR1 = P1^1;</span><br><span class="line">sbit ADDR2 = P1^2;</span><br><span class="line">sbit ADDR3 = P1^3;</span><br><span class="line">sbit ENLED = P1^4;</span><br><span class="line">unsigned char code LedChar[] = &#123; //数码管显示字符转换表</span><br><span class="line">    0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,</span><br><span class="line">    0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E</span><br><span class="line">&#125;;</span><br><span class="line">unsigned char LedBuff[6] = &#123; //数码管显示缓冲区，初值 0xFF 确保启动时都不亮</span><br><span class="line">    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF</span><br><span class="line">&#125;;</span><br><span class="line">void main()&#123;</span><br><span class="line">    unsigned char i = 0;  //动态扫描的索引</span><br><span class="line">    unsigned int cnt = 0;  //记录 T0 中断次数</span><br><span class="line">    unsigned long sec = 0;  //记录经过的秒数</span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line">    ENLED = 0;  //使能 U3，选择控制数码管</span><br><span class="line">    ADDR3 = 1;  //因为需要动态改变 ADDR0-2 的值，所以不需要再初始化了</span><br><span class="line">    TMOD = 0x01; //设置 T0 为模式 1</span><br><span class="line">    TH0 = 0xFC; //为 T0 赋初值 0xFC67，定时 1ms</span><br><span class="line">    TL0 = 0x67;</span><br><span class="line">    TR0 = 1;  //启动 T0</span><br><span class="line">   </span><br><span class="line">    while (1)&#123;</span><br><span class="line">        if (TF0 == 1)&#123;  //判断 T0 是否溢出</span><br><span class="line">            TF0 = 0;  //T0 溢出后，清零中断标志</span><br><span class="line">            TH0 = 0xFC;  //并重新赋初值</span><br><span class="line">            TL0 = 0x67;</span><br><span class="line">            cnt++;  //计数值自加 1</span><br><span class="line">       </span><br><span class="line">            if (cnt &gt;= 1000)&#123;  //判断 T0 溢出是否达到 1000 次</span><br><span class="line">                cnt = 0;  //达到 1000 次后计数值清零</span><br><span class="line">                sec++;  //秒计数自加 1</span><br><span class="line">               </span><br><span class="line">                //以下代码将 sec 按十进制位从低到高依次提取并转为数码管显示字符</span><br><span class="line">                LedBuff[0] = LedChar[sec%10];</span><br><span class="line">                LedBuff[1] = LedChar[sec/10%10];</span><br><span class="line">                LedBuff[2] = LedChar[sec/100%10];</span><br><span class="line">                LedBuff[3] = LedChar[sec/1000%10];</span><br><span class="line">                LedBuff[4] = LedChar[sec/10000%10];</span><br><span class="line">                LedBuff[5] = LedChar[sec/100000%10];</span><br><span class="line">            &#125;</span><br><span class="line">            //以下代码完成数码管动态扫描刷新</span><br><span class="line">            switch (i)&#123;</span><br><span class="line">                case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=LedBuff[0]; break;</span><br><span class="line">                case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=LedBuff[1]; break;</span><br><span class="line">                case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=LedBuff[2]; break;</span><br><span class="line">                case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=LedBuff[3]; break;</span><br><span class="line">                case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=LedBuff[4]; break;</span><br><span class="line">                case 5: ADDR2=1; ADDR1=0; ADDR0=1; i=0; P0=LedBuff[5]; break;</span><br><span class="line">                default: break;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>程序完成的功能是一模一样的，但大家看一下，switch 语句是不是比 if…else 语句显得要整齐清爽呢。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2014/12/01/mcu037/" rel="next" title="6.3、C语言switch语句">
                <i class="fa fa-chevron-left"></i> 6.3、C语言switch语句
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2014/12/01/mcu039/" rel="prev" title="6.5、单片机数码管显示消隐">
                6.5、单片机数码管显示消隐 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
